﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Irony.Ast;
using Irony.Parsing;

namespace ConciseMarkupLanguage.Ast
{
    class ForeachNode : AstNode
    {
        public override void Init(ParsingContext context, ParseTreeNode treeNode)
        {
            base.Init(context, treeNode);
            var verb = treeNode.ChildNodes[2].FindTokenAndGetText();
            if (verb == "in")
            {
                AddChild("var", treeNode.ChildNodes[1]);
                AddChild("list", treeNode.ChildNodes[3]);
            }
            else
            {
                AddChild("list", treeNode.ChildNodes[1]);
                AddChild("var", treeNode.ChildNodes[3]);
            }
        }
    }
}
